package org.javaboy.curator;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;

public class CuratorDemo {
    public static void main(String[] args) throws Exception {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.newClient("s2.javaboy.org:2181", 5000, 10000, retryPolicy);
        //建立连接
        client.start();
        //创建节点
        String s = client.create()
                .withMode(CreateMode.PERSISTENT)
                .forPath("/javaboy", "hello javaboy".getBytes());
        System.out.println("s = " + s);
        String s1 = client.create().creatingParentsIfNeeded()
                .withMode(CreateMode.PERSISTENT_SEQUENTIAL)
                .forPath("/javaboy/test/zhangsan", "hello javaboy".getBytes());
        System.out.println("s1 = " + s1);
    }
}
